home *** CD-ROM | disk | FTP | other *** search
/ Let's Discover Louisiana / Let's Discover Louisiana.iso / pc / FILES / FUND.dxr / 00305_Stretch.ls < prev    next >
Encoding:
Text File  |  2002-12-03  |  7.3 KB  |  179 lines

  1. property appearWhen, stretchDuration, direction, spriteNum, mySprite, myStartFrame, myEndFrame, myOriginalMember, myOriginalImage, myTransitionMember
  2.  
  3. on beginSprite me
  4.   me.convertAppearance()
  5.   me.convertDirection()
  6.   mySprite = sprite(spriteNum)
  7.   myOriginalMember = mySprite.member
  8.   myOriginalImage = image(myOriginalMember.width, myOriginalMember.height, 32)
  9.   case myOriginalMember.type of
  10.     #bitmap:
  11.       myOriginalImage = myOriginalMember.image
  12.       if not myOriginalMember.useAlpha then
  13.         myOriginalImage.setAlpha(255)
  14.       end if
  15.     #text, #vectorShape, #flash:
  16.       if myOriginalMember.type = #text then
  17.         mySprite.rect = mySprite.rect
  18.       end if
  19.       if mySprite.ink = 0 then
  20.         case myOriginalMember.type of
  21.           #text, #flash:
  22.             myOriginalImage.fill(myOriginalImage.rect, myOriginalMember.bgColor)
  23.           #vectorShape:
  24.             myOriginalImage.fill(myOriginalImage.rect, myOriginalMember.backgroundColor)
  25.         end case
  26.         myOriginalImage.copyPixels(myOriginalMember.image, myOriginalMember.rect, myOriginalImage.rect, [#maskImage: myOriginalMember.image.extractAlpha()])
  27.       else
  28.         myOriginalImage = myOriginalMember.image
  29.       end if
  30.   end case
  31.   case appearWhen of
  32.     #start:
  33.       myStartFrame = mySprite.startFrame
  34.       myEndFrame = myStartFrame + stretchDuration - 1
  35.     #end:
  36.       myEndFrame = mySprite.endFrame
  37.       myStartFrame = myEndFrame - stretchDuration + 1
  38.   end case
  39.   myTransitionMember = new(#bitmap, castLib(mySprite.castLibNum))
  40.   myTransitionMember.image = image(myOriginalMember.width, myOriginalMember.height, 32, 8)
  41.   myTransitionMember.regPoint = myOriginalMember.regPoint
  42.   myTransitionMember.useAlpha = 1
  43. end
  44.  
  45. on endSprite me
  46.   mySprite.member = myOriginalMember
  47.   erase(myTransitionMember)
  48. end
  49.  
  50. on prepareFrame me
  51.   if (the frame >= myStartFrame) and (the frame <= myEndFrame) then
  52.     elapsedFrames = the frame - myStartFrame + 1
  53.     if appearWhen = #end then
  54.       elapsedFrames = stretchDuration - elapsedFrames
  55.     end if
  56.     memberRect = myTransitionMember.rect
  57.     case direction of
  58.       #lefttoright, #righttoleft:
  59.         destRect = memberRect * rect(1, 1, elapsedFrames, 1) / rect(1, 1, stretchDuration, 1)
  60.       #bottomtotop, #toptobottom:
  61.         destRect = memberRect * rect(1, 1, 1, elapsedFrames) / rect(1, 1, 1, stretchDuration)
  62.       otherwise:
  63.         destRect = memberRect * rect(1, 1, elapsedFrames, elapsedFrames) / rect(1, 1, stretchDuration, stretchDuration)
  64.     end case
  65.     case appearWhen of
  66.       #start:
  67.         case direction of
  68.           #righttoleft:
  69.             destRect = offset(destRect, memberRect.width - destRect.width, 0)
  70.           #lefttoright:
  71.             nothing()
  72.           #bottomtotop:
  73.             destRect = offset(destRect, 0, memberRect.height - destRect.height)
  74.           #toptobottom:
  75.             nothing()
  76.           #bottomlefttotopright:
  77.             destRect = offset(destRect, 0, memberRect.height - destRect.height)
  78.           #bottomrighttotopleft:
  79.             destRect = offset(destRect, memberRect.width - destRect.width, memberRect.height - destRect.height)
  80.           #toprighttobottomleft:
  81.             destRect = offset(destRect, memberRect.width - destRect.width, 0)
  82.           #toplefttobottomright:
  83.             nothing()
  84.           #center:
  85.             destRect = offset(destRect, (memberRect.width - destRect.width) / 2, (memberRect.height - destRect.height) / 2)
  86.         end case
  87.       #end:
  88.         case direction of
  89.           #lefttoright:
  90.             destRect = offset(destRect, memberRect.width - destRect.width, 0)
  91.           #righttoleft:
  92.             nothing()
  93.           #toptobottom:
  94.             destRect = offset(destRect, 0, memberRect.height - destRect.height)
  95.           #bottomtotop:
  96.             nothing()
  97.           #toprighttobottomleft:
  98.             destRect = offset(destRect, 0, memberRect.height - destRect.height)
  99.           #toplefttobottomright:
  100.             destRect = offset(destRect, memberRect.width - destRect.width, memberRect.height - destRect.height)
  101.           #bottomlefttotopright:
  102.             destRect = offset(destRect, memberRect.width - destRect.width, 0)
  103.           #bottomrighttotopleft:
  104.             nothing()
  105.           #center:
  106.             destRect = offset(destRect, (memberRect.width - destRect.width) / 2, (memberRect.height - destRect.height) / 2)
  107.         end case
  108.     end case
  109.     myTransitionMember.image.setAlpha(0)
  110.     myTransitionMember.image.copyPixels(myOriginalImage, destRect, myTransitionMember.rect)
  111.     mySprite.member = myTransitionMember
  112.   else
  113.     mySprite.member = myOriginalMember
  114.   end if
  115. end
  116.  
  117. on convertAppearance me
  118.   case appearWhen of
  119.     "beginning of sprite":
  120.       appearWhen = #start
  121.     "end of sprite":
  122.       appearWhen = #end
  123.   end case
  124. end
  125.  
  126. on convertDirection me
  127.   case direction of
  128.     "left to right":
  129.       direction = #lefttoright
  130.     "right to left":
  131.       direction = #righttoleft
  132.     "bottom to top":
  133.       direction = #bottomtotop
  134.     "top to bottom":
  135.       direction = #toptobottom
  136.     "bottom left to top right":
  137.       direction = #bottomlefttotopright
  138.     "bottom right to top left":
  139.       direction = #bottomrighttotopleft
  140.     "top right to bottom left":
  141.       direction = #toprighttobottomleft
  142.     "top left to bottom right":
  143.       direction = #toplefttobottomright
  144.     "to or from center":
  145.       direction = #center
  146.   end case
  147. end
  148.  
  149. on isOKToAttach me, aSpriteType, aSpriteNum
  150.   isOK = 0
  151.   case aSpriteType of
  152.     #graphic:
  153.       case sprite(aSpriteNum).member.type of
  154.         #bitmap, #text, #flash, #vectorShape:
  155.           isOK = 1
  156.       end case
  157.   end case
  158.   return isOK
  159. end
  160.  
  161. on getPropertyDescriptionList me
  162.   props = [:]
  163.   props[#appearWhen] = [#comment: "When transition appears:", #format: #string, #default: "beginning of sprite", #range: ["beginning of sprite", "end of sprite"]]
  164.   firstFrame = sprite(the currentSpriteNum).startFrame
  165.   endFrame = sprite(the currentSpriteNum).endFrame
  166.   maxLength = endFrame - firstFrame + 1
  167.   props[#stretchDuration] = [#comment: "Duration:", #format: #integer, #default: min(maxLength, 10), #range: [#min: 1, #max: maxLength]]
  168.   props[#direction] = [#comment: "Direction:", #format: #string, #default: "left to right", #range: ["left to right", "right to left", "bottom to top", "top to bottom", "bottom left to top right", "bottom right to top left", "top right to bottom left", "top left to bottom right", "to or from center"]]
  169.   return props
  170. end
  171.  
  172. on getBehaviorTooltip
  173.   return "Creates a transition where the sprite appears to stretch into its final position or shrink from that position."
  174. end
  175.  
  176. on getBehaviorDescription
  177.   return "STRETCH TRANSITION" & RETURN & RETURN & "Drop this behavior onto a sprite to create an animation of the sprite stretching horizontally, vertically, or both directions" & RETURN & RETURN & "Select when the transition will take effect. " & "The duration controls the number of frames over which the transition occurs. " & "Direction controls the movement of the sprite" & RETURN & RETURN & "When this transition is used during authoring, and the movie is stopped the cast member it uses for the transition effect may not be erased" & RETURN & RETURN & "PERMITTED MEMBER TYPES:" & RETURN & "Bitmaps and text" & RETURN & RETURN & "PARAMETERS:" & RETURN & "* When transition appears - controls whether sprite moves on or off the stage" & RETURN & "* Duration - number of frames for the transition to take place" & RETURN & "* Direction - movement of sprite onto or off of the stage"
  178. end
  179.